## 基于QT界面框架的示例

set(TARGET_NAME ProjectWithQT)

##设置可执行程序
add_executable(${TARGET_NAME} ProjectWithQt.rc)

target_sources(${TARGET_NAME}
    PRIVATE  main.cpp
)

# 一旦要求构建公共组件示例，应用程序必须添加该清单文件，否则文字无法正常创建、编辑
if(BUILD_COMPONENTS_SAMPLE)
    target_sources(${TARGET_NAME} PRIVATE
        "${CMAKE_CURRENT_SOURCE_DIR}/CAXA2D.manifest"
    )
endif()

##设置源代码目录
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

# 提取所有的源文件(头文件和源文件分开提取)
file(GLOB_RECURSE  HEADER_FILES
    LIST_DIRECTORIES False  CONFIGURE_DEPENDS
    "${SOURCE_DIR}/*.h*"
)
file(GLOB_RECURSE  SRC_FILES
    LIST_DIRECTORIES False  CONFIGURE_DEPENDS
    "${SOURCE_DIR}/*.c*"
    "${SOURCE_DIR}/*.ui"
)

# 为VS设置源代码文件夹
source_group(
    TREE "${SOURCE_DIR}"
    PREFIX "Header Files"
    FILES ${HEADER_FILES}
)
source_group(
    TREE "${SOURCE_DIR}"
    PREFIX "Source Files"
    FILES ${SRC_FILES}
)

set_target_properties(${TARGET_NAME} PROPERTIES
    FOLDER "示例程序框架"
    LINK_FLAGS "/DELAYLOAD:UIPlatform.dll 
                /DELAYLOAD:GcmpDevService.dll 
                /DELAYLOAD:GcmpUiInterface.dll 
                /DELAYLOAD:GcmpJournalInterface.dll 
                /DELAYLOAD:GcmpGuiMainFrameInterface.dll
                /DELAYLOAD:GcmpModelInterface.dll
				/DELAYLOAD:GcmpRenderingInterface.dll"
)

##以下指令会移除命令行窗体,直接展示应用程序界面
find_package(Qt5 COMPONENTS Widgets CONFIG)
#qt5_add_resources(QRC_FILES 
#    "${CMAKE_CURRENT_SOURCE_DIR}/Resource.qrc"
#)
set_target_properties(${TARGET_NAME} PROPERTIES
    WIN32_EXECUTABLE TRUE
)

# 指定源文件
target_sources(${TARGET_NAME}
    PRIVATE  ${SRC_FILES}
    PRIVATE  ${HEADER_FILES}
    PRIVATE  ${QRC_FILES}
)

##设置依赖库
target_link_libraries(${TARGET_NAME}
    PRIVATE Qt5::Widgets
    #Plugin
    PRIVATE Gcmp::All UIPlatform
)

#拷贝Data文件
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory  ${CMAKE_CURRENT_SOURCE_DIR}/../Data $<TARGET_FILE_DIR:${TARGET_NAME}>/
)

## 拷贝依赖的运行时资源
DeployGcmpRuntime(${TARGET_NAME})